﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FluentValidation;
using SilverlightApplication1.ServiceReferenceHH;

namespace SilverlightApplication1.Validators
{
    public class HanghoaValidator:AbstractValidator<MatHang>
    {
        public HanghoaValidator()
        {
            RuleFor(x => x.Tenmh).NotEmpty()
                .WithMessage("Nhap ten mat hang");
            RuleFor(x => x.Dongia).NotEmpty()
                .WithMessage("Nhap don gia");
            RuleFor(x => x.Ngayban)
                .Must(BeAValidDateOfBirth)
                .WithMessage("Ngay ban duoi 5 nam");
                
        }

        private bool BeAValidDateOfBirth(DateTime? dateOfBirth)
        {
            if (dateOfBirth == null) return false;
            if (dateOfBirth.Value > DateTime.Today || dateOfBirth < DateTime.Today.AddYears(-5))
                return false;
            return true;
        }
        
    }
}
